/**
 * Created by zpc on 2018/5/10.
 */
$(function(){

    messageBoardList(1);

    $(".content .right_box .publish_btn").click(function(){
        $(".information_box").show();
        $(".obscure").show();
    });
    $(".information_box .esc_01").click(function(){
        $(".information_box").hide();
        $(".obscure").hide();
    });
    $(".information_box .send").click(function(){
        addMessageBoard();
        $(".information_box").hide();
        $(".message_box").show();
    });
    $(".message_box .close").click(function(){
        $(".message_box").hide();
        $(".obscure").hide();
    });
    
    
    
    

    
    
})


function messageBoardList(page) {

    var postData = {pageSize:8, page:page,status:1 };
    //pageSize 一页好多条  page当前页
    $.ajax({
        type: "POST",
        url: "/pioneer/messageBoard/getMessageBoardList.html",
        dataType: "json",
        async: true,
        data: postData,
        success: function (data){
            console.log(data.data);

            if(data.code!=1){
                alert(data.msg);
                return;
            }else {
                messageList(data.data);
            }
            if (page > 1) {
                return;
            }
            laypage({
                cont: 'demo1',
                skin: '#f59d00',
                pages: data.data.pages,
                jump: function (obj, first) {
                    if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                        messageBoardList(obj.curr);
                    }

                }
            });
        }
    })
}

function messageList(data){
    console.log(data);
    var html='';
    for(var i=0; i<data.list.length; i++ ){
        html+='<li>';
        html+='<div class="img_box">';
        html+='<img src="'+ data.list[i].headPic +'" alt="">';
        html+='</div>';
        html+='<div class="box_h5">';
        html+='<h5>'+ data.list[i].userName +'</h5>';
        html+='<span class="cont">'+ data.list[i].message +'</span>';
        html+='</div>';
        html+='</li>';
    }
    console.log("===============>>>>>>>>>>>>111111111111");
    $('.content .box_u ul').html(html);
}













function addMessageBoard() {
    var message=$(".information_box .information").val();
    var postData={message:message,type:1,status:0}
    var message_01=$(".message_box .message");
    $.ajax({
        type: 'POST',
        url: '/pioneer/messageBoard/addMessageBoard.html',
        async: true,
        data:postData,
        dataType:'json',
        success: function(data){
            console.log(data);
            if( data.code != 1 ) {
                message_01.html(data.msg);

            }else {
                message_01.html(data.msg);
            }
        }
    })
}